package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.common.RedisConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Member;
import com.itheima.health.pojo.Order;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.MemberService;
import com.itheima.health.service.OrderService;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.service.SetMealService;
import com.itheima.health.vo.OrderSubmitParam;
import com.itheima.health.vo.OrderVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

/**
 * 预约控制器
 */
@RestController
@RequestMapping("/mobile/order")
@Slf4j
@Api(tags = "手机端订单接口")
public class MobileOrderController {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private OrderService orderService;
    @PostMapping("/submit")
    public Result submit(@RequestBody OrderSubmitParam orderSubmitParam){
        String validateCodeInRedis=redisTemplate.opsForValue().get("telephone")+"";
        String validateCode=orderSubmitParam.getValidateCode();
        log.info(validateCodeInRedis);
        log.info(validateCode);
        if (validateCodeInRedis!=null&&validateCode!=null&&validateCode.equals(validateCodeInRedis)){
            Result result=orderService.order(orderSubmitParam);
            return result;
        }else {
            return new Result(false,MessageConst.VALIDATECODE_ERROR);
        }
    }
/*
订单数据展示
 */
@GetMapping("/findById")
    public Result findById(String id){
    log.info(id);
    OrderVO list=orderService.SelectOrdersById(id);
    return new Result(true,MessageConst.QUERY_ORDER_SUCCESS,list);

}

}
